﻿@model InstallModel
@using Nop.Core.Infrastructure;
@using Nop.Web.Models.Install;
@using Nop.Web.Infrastructure.Installation;
@{
    //localization service for installation service
    //we do not use standard nopCommerce localization because database is not installed yet
    //locale resources for installation process are stored into \App_Data\Localization\Installation directory
    var ILS = EngineContext.Current.Resolve<IInstallationLocalizationService>();
}
<!DOCTYPE html>
<html>
<head>
    <title>@ILS.GetResource("Title")</title>
    <meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
    @if (ILS.GetCurrentLanguage().IsRightToLeft)
    {
        <link href="@Url.Content("~/Content/bootstrap/bootstrap-rtl.css")" rel="stylesheet"/>        
        <link href="@Url.Content("~/Content/Install/style.rtl.css")" type="text/css" rel="stylesheet" />
    }
    else
    {
        <link href="@Url.Content("~/Content/bootstrap/bootstrap.min.css")" rel="stylesheet"/>
        <link href="@Url.Content("~/Content/Install/style.css")" type="text/css" rel="stylesheet" />
    }
    <script src="@Url.Content("~/Scripts/jquery-1.7.1.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/public.common.js")" type="text/javascript"></script>

    @if (ILS.GetCurrentLanguage().IsRightToLeft)
    {
        <script src="@Url.Content("~/Scripts/bootstrap-rtl.js")" type="text/javascript"></script>
    }
    else
    {
        <script src="@Url.Content("~/Scripts/bootstrap.min.js")" type="text/javascript"></script>
    }

</head>
<body class="container-main">
    @using (Html.BeginForm("Index", "Install", FormMethod.Post, new { id = "installation-form" }))
    {
        <script type="text/javascript">
            $(document).ready(function () {
                $('#installation-form').submit(function () {
                    if ($('#installation-form').valid()) {
                        window.setTimeout(function () {
                            $(".throbber").show();
                        }, 1000);

                        $('input[type=submit]', this).attr('disabled', 'disabled');
                    }
                });
            });

            $(document).ready(function () {
                $('input:radio[name=DataProvider]').click(toggleProvider);
                $('input:radio[name=SqlConnectionInfo]').click(toggleSqlConnectionInfo);
                $('input:radio[name=SqlAuthenticationType]').click(toggleSqlAuthenticationType);
                $("input:checkbox[name=UseCustomCollation]").click(toggleCollation);

                toggleProvider();
                toggleSqlConnectionInfo();
                toggleSqlAuthenticationType();
                toggleCollation();
            });


            function toggleProvider() {
                var selectedProvider = $("input[name=DataProvider]:checked").attr('id');
                if (selectedProvider == 'provider_sqlce') {
                    $('#sqlConnectionInfo').hide();
                }
                else if (selectedProvider == 'provider_sqlserver') {
                    $('#sqlConnectionInfo').show();
                }
            }

            function toggleSqlConnectionInfo() {
                var selectedProvider = $("input[name=SqlConnectionInfo]:checked").attr('id');
                if (selectedProvider == 'sqlconnectioninfo_values') {
                    $('#sqlDatabaseInfo').show();
                    $('#sqlDatabaseConnectionString').hide();
                }
                else if (selectedProvider == 'sqlconnectioninfo_raw') {
                    $('#sqlDatabaseInfo').hide();
                    $('#sqlDatabaseConnectionString').show();
                }
            }

            function toggleSqlAuthenticationType() {
                var selectedProvider = $("input[name=SqlAuthenticationType]:checked").attr('id');
                if (selectedProvider == 'sqlauthenticationtype_sql') {
                    $('#pnlSqlServerUsername').show();
                    $('#pnlSqlServerPassword').show();
                }
                else if (selectedProvider == 'sqlauthenticationtype_windows') {
                    $('#pnlSqlServerUsername').hide();
                    $('#pnlSqlServerPassword').hide();
                }
            }


            function toggleCollation() {
                if ($('#UseCustomCollation').is(':checked')) {
                    $('#Collation').show();
                }
                else {
                    $('#Collation').hide();
                }
            }

        </script>

        <div class="tm_pad-shadow">
            <div class="tm_lifted">
                <div class="tm_text-shadow">

                    <div style="text-align: center;"><span class="header-text">@ILS.GetResource("Title")</span></div>
                    <br />
                    <div class="alert alert-info">
                        <strong>@ILS.GetResource("Tooltip2")</strong>
                    </div>

                    <div style="color: Red;">
                        @Html.ValidationSummary(false)
                    </div>

                    <div class="bs-docs">
                        <div class="bs-doc-titile">@ILS.GetResource("InstallationLanguage")</div>
                        <div class="input-group">
                            <span class="input-group-addon inputLable">@ILS.GetResource("SelectInstallationLanguage")</span>
                            @Html.DropDownList("language", Model.AvailableLanguages, new { onchange = "window.location.href = this.value;", style = "width:310px;", @class = "form-control" })
                        </div>
                        <br />
                    </div>

                    <div class="bs-docs">
                        <div class="bs-doc-titile">@ILS.GetResource("StoreInformation")</div>
                        <div class="input-group">
                            <span class="input-group-addon inputLable">@ILS.GetResource("AdminEmail")</span>
                            @Html.TextBoxFor(x => x.AdminEmail, new { @class = "form-control", style = "width:300px; direction: ltr;" })
                        </div>
                        @Html.ValidationMessage("AdminEmail", null, new { @class = "help-inline" })
                        <br />

                        <div class="input-group">
                            <span class="input-group-addon inputLable">@ILS.GetResource("AdminPassword")</span>
                            @Html.PasswordFor(x => x.AdminPassword, new { @class = "form-control", style = "width:300px; direction: ltr;" })
                        </div>
                        @Html.ValidationMessage("AdminPassword", null, new { @class = "help-inline" })

                        <br />
                        <div class="input-group">
                            <span class="input-group-addon inputLable">@ILS.GetResource("ConfirmPassword")</span>
                            @Html.PasswordFor(x => x.ConfirmPassword, new { @class = "form-control", style = "width:300px; direction: ltr;" })
                        </div>
                        @Html.ValidationMessage("ConfirmPassword", null, new { @class = "help-inline" })
                        <br />
                    </div>

                    <div class="bs-docs">
                        <div class="bs-doc-titile">@ILS.GetResource("DatabaseInformation")</div>

                        <table class="table">
                            <thead>
                                <tr>

                                    @if (!Model.DisableSqlCompact)
                                    {
                                        <td>
                                            <label class="radio">
                                                @Html.RadioButton("DataProvider", "sqlce", (Model.DataProvider == "sqlce"), new { id = "provider_sqlce" })
                                                @ILS.GetResource("SqlCompact")
                                            </label>
                                        </td>
                                    }
                                    <td>
                                        <label class="radio">
                                            @Html.RadioButton("DataProvider", "sqlserver", (Model.DataProvider == "sqlserver"), new { id = "provider_sqlserver" })
                                            @ILS.GetResource("SqlStandard")
                                        </label>
                                    </td>
                                </tr>
                            </thead>
                        </table>
                        <hr class="databases" />

                        <div id="sqlConnectionInfo">
                            <table class="table">
                                <thead>
                                    <tr>
                                        <td style="width: 50%;">
                                            <label class="radio">
                                                @Html.RadioButton("SqlConnectionInfo", "sqlconnectioninfo_values", (Model.SqlConnectionInfo == "sqlconnectioninfo_values"), new { id = "sqlconnectioninfo_values" })
                                                @ILS.GetResource("ConnectionStringValues")
                                            </label>
                                        </td>
                                        <td style="width: 50%;">
                                            <label class="radio">
                                                @Html.RadioButton("SqlConnectionInfo", "sqlconnectioninfo_raw", (Model.SqlConnectionInfo == "sqlconnectioninfo_raw"), new { id = "sqlconnectioninfo_raw" })
                                                @ILS.GetResource("RawConnectionString")
                                            </label>
                                        </td>
                                    </tr>
                                </thead>
                            </table>

                            <div id="sqlDatabaseInfo">
                                <div class="input-group">
                                    <span class="input-group-addon inputLable">@ILS.GetResource("SqlServerName")</span>
                                    @Html.TextBoxFor(x => x.SqlServerName, new { @class = "form-control", style = "width:300px; direction: ltr;" })
                                </div>
                                @Html.ValidationMessage("SqlServerName", null, new { @class = "help-inline" })
                                <br />
                                <div class="input-group">
                                    <span class="input-group-addon inputLable">@ILS.GetResource("DatabaseName")</span>
                                    @Html.TextBoxFor(x => x.SqlDatabaseName, new { @class = "form-control", style = "width:300px; direction: ltr;" })
                                </div>
                                @Html.ValidationMessage("SqlDatabaseName", null, new { @class = "help-inline" })
                                <br />
                                <table class="table">
                                    <thead>
                                        <tr>
                                            <td style="width: 50%;">
                                                <label class="radio">
                                                    @Html.RadioButton("SqlAuthenticationType", "sqlauthentication", (Model.SqlAuthenticationType == "sqlauthentication"), new { id = "sqlauthenticationtype_sql" })
                                                    @ILS.GetResource("SqlAuthentication")
                                                </label>
                                            </td>
                                            <td style="width: 50%;">
                                                <label class="radio">
                                                    @Html.RadioButton("SqlAuthenticationType", "windowsauthentication", (Model.SqlAuthenticationType == "windowsauthentication"), new { id = "sqlauthenticationtype_windows" })
                                                    @ILS.GetResource("WindowsAuthentication")
                                                </label>
                                            </td>
                                        </tr>
                                    </thead>
                                </table>

                                <div class="input-group" id="pnlSqlServerUsername">
                                    <span class="input-group-addon inputLable">@ILS.GetResource("SqlServerUsername")</span>
                                    @Html.TextBoxFor(x => x.SqlServerUsername, new { @class = "form-control", style = "width:300px; direction: ltr;" })
                                </div>
                                @Html.ValidationMessage("SqlServerUsername", null, new { @class = "help-inline" })
                                <br />
                                <div class="input-group" id="pnlSqlServerPassword">
                                    <span class="input-group-addon inputLable">@ILS.GetResource("SqlServerPassword")</span>
                                    @Html.PasswordFor(x => x.SqlServerPassword, new { @class = "form-control", style = "width:300px; direction: ltr;" })
                                </div>
                                @Html.ValidationMessage("SqlServerPassword", null, new { @class = "help-inline" })
                                <br />
                            </div>

                            <div id="sqlDatabaseConnectionString">
                                <div class="input-group">
                                    <span class="input-group-addon inputLable">@ILS.GetResource("ConnectionString")</span>
                                    @Html.TextBoxFor(x => x.DatabaseConnectionString, new { @class = "form-control", style = "width:525px; direction: ltr;" })
                                </div>
                                @Html.ValidationMessage("DatabaseConnectionString", null, new { @class = "help-inline" })
                                <span class="hint">@ILS.GetResource("Example"):<br />
                                    <br />
                                    <code>Data Source=sqlServerName;Initial Catalog=dbName;Persist Security Info=True;UserID=userName;Password=password</code></span>
                            </div>
                            <hr class="databases" />
                            <div class="input-group">
                                <span class="input-group-addon">@Html.CheckBoxFor(x => x.SqlServerCreateDatabase)</span>
                                <span class="form-control">@ILS.GetResource("CreateDatabaseIfDoesNotExist")</span>
                            </div>
                            <br />
                            <div class="input-group">
                                <span class="input-group-addon">@Html.CheckBoxFor(x => x.UseCustomCollation)</span>
                                <span class="form-control">@ILS.GetResource("CustomCollation")</span>
                            </div>
                            <br />
                            <div class="input-group" id="Collation">
                                <span class="input-group-addon inputLable">@ILS.GetResource("CustomCollation")</span>
                                @Html.TextBoxFor(x => x.Collation, new { @class = "form-control", style = "direction: ltr;" })
                            </div>
                            <br />
                        </div>

                        @if (!Model.DisableSampleDataOption)
                        {
                            <div class="input-group">
                                <span class="input-group-addon">@Html.CheckBoxFor(x => x.InstallSampleData)</span>
                                <span class="form-control">@ILS.GetResource("CreateSampleData")</span>
                            </div>
                            <br />
                        }

                    </div>

                    <div class="form-footer">
                        <a href="@Url.Action("RestartInstall", "Install")" title="@ILS.GetResource("RestartInstallationTooltip")" class="btn">@ILS.GetResource("RestartInstallation")</a>
                        <input class="btn btn-primary" type="submit" value="@ILS.GetResource("Install")" style="width: 100px;" />
                    </div>
                </div>
            </div>
        </div>  
        
        <div class="throbber">
            <div class="curtain">
            </div>
            <div class="curtain-content">
                <div>
                    <h1 class="throbber-header">
                        @ILS.GetResource("Installing")</h1>
                    <p>
                        <img src="@Url.Content("~/content/install/images/install-synchronizing.gif")" alt="" />
                    </p>
                </div>
            </div>
        </div>
    }
</body>
</html>
